package geektime.spring.springbucks;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisSentinelPool;
import redis.clients.util.Pool;

public class MyJedisExample {

    public static void main(String[] args) {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        String host = "localhost";
        JedisPool jedisPool = new JedisPool(jedisPoolConfig, host);
        try(Jedis jedis = jedisPool.getResource()) {
            jedis.set("aaa", "bbb");
        }
    }

    private static class JedisPoolConfig extends GenericObjectPoolConfig {
        public JedisPoolConfig() {
            // defaults to make your life with connection pool easier :)
            setTestWhileIdle(true);
            setMinEvictableIdleTimeMillis(60000);
            setTimeBetweenEvictionRunsMillis(30000);
            setNumTestsPerEvictionRun(-1);
            setTestOnBorrow(true);
            setMaxTotal(5);
            setMaxIdle(5);
        }
    }
}
